]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
popup-menu: Allow updating combobox items with scroll wheel
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 1 Sep 2011 17:33:31 +0000 (19:33 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 2 Sep 2011 16:08:54 +0000 (18:08 +0200)
Rather than opening the combobox menu, allow using the scroll wheel
to cycle through the visible items.

https://bugzilla.gnome.org/show_bug.cgi?id=657973

js/ui/popupMenu.js

index c272de72373f226e104db457f80a9e5d30dbb5c8..2551d687e25780e69b1fae80e409a39c09d072d8 100644 (file)
@@ -1507,6 +1507,10 @@ PopupComboMenu.prototype = {
         }
 
         this._getMenuItems()[position].actor.visible = visible;
+    },
+
+    getItemVisible: function(position) {
+        return this._getMenuItems()[position].actor.visible;
     }
 };
 
@@ -1533,6 +1537,8 @@ PopupComboBoxMenuItem.prototype = {
         if (params.style_class)
             this._menu.actor.add_style_class_name(params.style_class);
 
+        this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
+
         this._activeItemPos = -1;
         this._items = [];
     },
@@ -1551,6 +1557,33 @@ PopupComboBoxMenuItem.prototype = {
         return null;
     },
 
+    _onScrollEvent: function(actor, event) {
+        if (this._activeItemPos == -1)
+            return;
+
+        let position = this._activeItemPos;
+        let direction = event.get_scroll_direction();
+        if (direction == Clutter.ScrollDirection.DOWN) {
+            while (position < this._items.length - 1) {
+                position++;
+                if (this._menu.getItemVisible(position))
+                    break;
+            }
+        } else if (direction == Clutter.ScrollDirection.UP) {
+            while (position > 0) {
+                position--;
+                if (this._menu.getItemVisible(position))
+                    break;
+            }
+        }
+
+        if (position == this._activeItemPos)
+            return;
+
+        this.setActiveItem(position);
+        this.emit('active-item-changed', position);
+    },
+
     activate: function(event) {
         let topMenu = this._getTopMenu();
         if (!topMenu)